<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../00.依赖包/react.development.js"></script>
  <script src="../00.依赖包/react-dom.development.js"></script>
  <script src="../00.依赖包/babel.min.js"></script>
</head>

<body>
  <button id="btn">点击按钮,重新渲染虚拟dom</button>
  <div id="app"></div>
  <script type="text/babel">
    //因为diff算法是旧的虚拟dom和新的虚拟dom进行比较
    //diff算法只会同层级比较 不会跨级比较
    //diff算法在某个层级比较一致的话,会进入层级内部再次比较,默认按照DOM书写顺序进行比较
    const arr =['html','css','js']
    const vDom = (
      <ul>
        {
          arr.map(item=>{
            return <li key={item}>{item}</li>
          })
        }
        </ul>
    )
    const root =  ReactDOM.createRoot(document.getElementById('app'))
    root.render(vDom)
    //给按钮绑定事件
    //在数组的前面添加一个元素，会破坏原来的虚拟dom解构 导致页面元素重新加载
    const oBtn = document.getElementById('btn')
    let i = 0
    oBtn.onclick=function(){
      
      arr.unshift('react'+ i++)
      const vDom = (
        <ul>
          {
            arr.map(item=>{
            return <li key={item}>{item}</li>
          })
          }
        </ul>
      
    )
    root.render(vDom)
    }

    
  </script>
</body>

</html>